package com.lekang.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lekang.common.annotation.Log;
import com.lekang.common.core.controller.BaseController;
import com.lekang.common.core.domain.AjaxResult;
import com.lekang.common.enums.BusinessType;
import com.lekang.domain.NursingPlan_yyh;
import com.lekang.service.INursingPlan_yyhService;
import com.lekang.common.utils.poi.ExcelUtil;
import com.lekang.common.core.page.TableDataInfo;

/**
 * 护理计划Controller
 * 
 * @author ruoyi
 * @date 2025-10-13
 */
@RestController
@RequestMapping("/system/plan")
public class NursingPlan_yyhController extends BaseController
{
    @Autowired
    private INursingPlan_yyhService nursingPlan_yyhService;

    /**
     * 查询护理计划列表
     */
    @PreAuthorize("@ss.hasPermi('system:plan:list')")
    @GetMapping("/list")
    public TableDataInfo list(NursingPlan_yyh nursingPlan_yyh)
    {
        startPage();
        List<NursingPlan_yyh> list = nursingPlan_yyhService.selectNursingPlan_yyhList(nursingPlan_yyh);
        for(NursingPlan_yyh pl : list){
            System.out.println("==================================="+pl);
        }
        return getDataTable(list);
    }

    /**
     * 查询计划名是否重复
     * @param nursingPlan_yyh
     * @return
     */
    @PreAuthorize("@ss.hasPermi('system:plan:list')")
    @GetMapping("/selectName")
    public AjaxResult selectName(NursingPlan_yyh nursingPlan_yyh)
    {
        startPage();
        int i = nursingPlan_yyhService.selectNursingPlanName(nursingPlan_yyh);
        return AjaxResult.success(i);
    }


    /**
     * 导出护理计划列表
     */
    @PreAuthorize("@ss.hasPermi('system:plan:export')")
    @Log(title = "护理计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NursingPlan_yyh nursingPlan_yyh)
    {
        List<NursingPlan_yyh> list = nursingPlan_yyhService.selectNursingPlan_yyhList(nursingPlan_yyh);
        ExcelUtil<NursingPlan_yyh> util = new ExcelUtil<NursingPlan_yyh>(NursingPlan_yyh.class);
        util.exportExcel(response, list, "护理计划数据");
    }

    /**
     * 获取护理计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:plan:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(nursingPlan_yyhService.selectNursingPlan_yyhById(id));
    }

    /**
     * 新增护理计划
     */
    @PreAuthorize("@ss.hasPermi('system:plan:add')")
    @Log(title = "护理计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NursingPlan_yyh nursingPlan_yyh)
    {
        return toAjax(nursingPlan_yyhService.insertNursingPlan_yyh(nursingPlan_yyh));
    }

    /**
     * 修改护理计划
     */
    @PreAuthorize("@ss.hasPermi('system:plan:edit')")
    @Log(title = "护理计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NursingPlan_yyh nursingPlan_yyh)
    {
        return toAjax(nursingPlan_yyhService.updateNursingPlan_yyh(nursingPlan_yyh));
    }

    /**
     * 删除护理计划
     */
    @PreAuthorize("@ss.hasPermi('system:plan:remove')")
    @Log(title = "护理计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(nursingPlan_yyhService.deleteNursingPlan_yyhByIds(ids));
    }
}
